package net.mysoft.budgetsoft.system.action;

import net.mysoft.budgetsoft.system.domain.TUser;
import net.mysoft.budgetsoft.system.service.LoginService;
import net.mysoft.framework.base.BaseAction;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

/**
 * 登陆action
 * @author kangrui
 *
 */
@Namespace("/login")
@Scope("prototype")
@Controller
public class LoginAction extends BaseAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = -8959043905419751909L;
	
	@Autowired
	private LoginService loginService;
	
	private String name;
	private String pwd;
	
	/**
	 * 登陆验证
	 * @return
	 */
	@Action("check")
	public String check() {
		//System.err.println(name+","+pwd);
		TUser tuser = loginService.check(name, pwd);
		if(tuser!=null) {
			super.getSession().setAttribute(LOGIN_USER, tuser);
			super.success(null);
		} else {
			super.fail("用户名或密码错误！！");
		}
		return null;
	}
	
	/**
	 * 登出
	 * @return
	 */
	@Action("logout")
	public String logout() {
		getSession().removeAttribute(LOGIN_USER);
		return "noSession";
	}

	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getPwd() {
		return pwd;
	}
	public void setPwd(String pwd) {
		this.pwd = pwd;
	}


}
